import { BasicFetchResult } from '../model/baseModel';
import { defHttp } from '@/utils/http/axios';
import { downloadBlob } from '@/utils/file/download';
enum Api {
  SysConfigApi = '/sysConfig',
}
/**
 * 查询系统参数配置表分页
 * @author frank
 * @date 2022-10-19 16:03:06
 */
export const getSysConfigPage = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({ url: Api.SysConfigApi + '/page', params });
/**
 * 添加系统参数配置表
 * @author frank
 * @date 2022-10-19 16:03:06
 */
export const addSysConfig = (params?: any) =>
  defHttp.post({ url: Api.SysConfigApi + '/add', params });
/**
 * 修改系统参数配置表
 * @author frank
 * @date 2022-10-19 16:03:06
 */
export const editSysConfig = (params?: any) =>
  defHttp.post({ url: Api.SysConfigApi + '/edit', params });

/**
 * 删除系统参数配置表
 * @author frank
 * @date 2022-10-19 16:03:06
 */
export const deleteSysConfig = (ids: string[]) =>
  defHttp.post({ url: Api.SysConfigApi + '/delete', params: ids });
/**
 * 导出系统参数配置表
 * @author frank
 * @date 2022-10-19 16:03:06
 */
export const exportSysConfig = (params?: any) => {
  return new Promise<void>((resolve, reject) => {
    defHttp
      .get(
        { responseType: 'blob', url: Api.SysConfigApi + '/export', params },
        { isReturnNativeResponse: true },
      )
      .then((res) => {
        downloadBlob(res);
        resolve();
      })
      .catch(() => {
        reject();
      });
  });
};
